// const list = document.querySelectorAll('.list ul li')
// for(i=0;i<list.length;i++){
//     list[i].onclick = ()=>{
//         window.location.href = './Details.html'
//     }
// }
require(['./config'],()=>{
    require([ 'template', 'request','jquery'],(tmplate,req)=>{
        class List {
            constructor(){
                this.count = 0
                this.init()
                this.getNavData()
                this.gwc()
            }
            init(){
                const id = window.location.search.slice(3)
                // console.log(id)
                this.getData(id)
            }
            getData(id){
                req.getListData(id)
                    .then(res=>{
                        // console.log(res)
                        if(res.code ===200){
                            this.render1(res.data.items)
                        }
                    })
            }
            render1(obj){
                const {list,nextIndex,startIndex} = obj
                // console.log(list)
                const html = tmplate('templateList',{list})
                // console.log(html);
                $('.right ul').html(html)
            }
            getNavData(){
                req.getNav()
                .then(res =>{
                    if(res.code === 200){
                            this.render(res.data.list)
                    }
                })
            }
            render(res){
                console.log(res)
                // console.log($('.con ul'))
                const list = res.splice(1,7)
                const html = tmplate('templateNav',{list})
                $('.con ul').html(html)
            }
            gwc(){
                let prodList = localStorage.getItem('prodList')
                if(prodList){
                    prodList = JSON.parse(prodList)
                    prodList.forEach(item =>{
                        this.count += item.count
                    })
                }else{}
               $('.gwc').text(this.count)
            }
        }
        return new List()
    })
})